import { reolveTime, parseTime } from './index'
const filters = {
  defaultHead (value) {
    return value || 'http://oo6mi8i6z.bkt.clouddn.com/default-head.png'
  },

  fixed (value, count = 2, suffix = '') {
    if (!isNaN(value)) {
      return value.toFixed(count) + suffix
    } else {
      return '-'
    }
  },
  empty (value, placeholder = '-') {
    if (value === null || value === undefined || value === '') {
      return placeholder
    } else {
      return value
    }
  },
  price (value, suffix = '¥') {
    if (!isNaN(value)) {
      return suffix + (value / 100).toFixed(2)
    } else {
      return '-'
    }
  },
  datetime (value, format) {
    return value ? parseTime(reolveTime(value), format) : value
  },
  orgType (value) {
    switch (value) {
      case 1:
        return '学校'
      case 2:
        return '机构'
      case 3:
        return '赛事'
    }
  }
}

export default {
  install (vue, options) {
    for (const key in filters) {
      vue.filter(key, filters[key])
    }
  }
}
